package pers.itqiqi.spring5.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author kevin_琪琪
 * @version 1.0
 * @description
 * @date 2022-06-27 15:56
 */
// 增强类
@Component
@Aspect  // 生成代理对象
@Order(1)
public class UserProxy {

    @Pointcut("execution(* pers.itqiqi.spring5.aopanno.User.add(..))")
    public void pointDemo() {}

    // 前置通知
    // Before注解表示作为前置通知
    @Before("pointDemo()")
    public void before() {
        System.out.println("before.....");
    }

    // 最终通知
    @After("pointDemo()")
    public void after() {
        System.out.println("after...");
    }

    // 后置通知
    @AfterReturning("pointDemo()")
    public void afterReturning() {
        System.out.println("afterReturning...");
    }

    // 异常通知
    @AfterThrowing("pointDemo()")
    public void afterThrowing() {
        System.out.println("afterThrowing...");
    }

    // 环绕通知
    @Around("pointDemo()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前...");
        // 被增强的方法
        proceedingJoinPoint.proceed();
        System.out.println("环绕之后...");
    }

}
